package org.jeecg.modules.mall.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.jd.entity.JD_position;
import org.jeecg.modules.mall.entity.Taobao_cate;
import org.jeecg.modules.mall.mapper.Taobao_cateMapper;
import org.jeecg.modules.mall.service.ITaobao_cateService;
import org.jeecg.modules.mall.util.TaoBaoUtil;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 淘宝类目
 * @Author: jeecg-boot
 * @Date: 2020-06-12
 * @Version: V1.0
 */
@Service
public class Taobao_cateServiceImpl extends ServiceImpl<Taobao_cateMapper, Taobao_cate> implements ITaobao_cateService {

    @Override
    public List<Taobao_cate> initTaobaoCate() {
        String json = TaoBaoUtil.getTabobaoCate();
        JSONObject jsonObject = JSON.parseObject(json);
        String cateList = jsonObject.getString("data");
        List<Taobao_cate> taobao_cateList = JSON.parseArray(cateList, Taobao_cate.class);
        if (null != taobao_cateList && taobao_cateList.size() > 0) {
            for (Taobao_cate taobao_cate : taobao_cateList) {
                Taobao_cate old_taobao_cate = this.getById(taobao_cate.getId());
                if (null == old_taobao_cate) {
                    this.save(taobao_cate);
                } else {
                    this.updateById(taobao_cate);
                }
            }
        }
        return taobao_cateList;
    }
}
